package com.product.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.product.dao.ProductCategoryDao;
import com.product.entity.ProductCategory;
import com.product.service.ICategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @program: Member_Perks_Store
 * @description:
 * @author: 无恙
 * @create: 2024-06-20 10:04
 **/

@Service
public class ICategoryImpl extends ServiceImpl<ProductCategoryDao, ProductCategory> implements ICategory {

    @Autowired
    private ProductCategoryDao productCategoryDao;

    @Override
    public Map<Long, String> getCategoryList() {
        List<ProductCategory> productCategories = productCategoryDao.selectList(null);

        if (productCategories != null && productCategories.size() > 0) {
            return productCategories.stream().collect(
                    Collectors.toMap(ProductCategory::getId, ProductCategory::getName));
        }

        return Collections.emptyMap();
    }
}
